home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue31 / hash2 / TstHshLP.dpr < prev    next >
Encoding:
Text File  |  1997-11-29  |  1.7 KB  |  62 lines

  1. program TstHshLP;
  2.  
  3. uses
  4.   SysUtils,
  5.   HashLinP in 'HashLinP.pas';
  6.  
  7. const
  8.   ElementCount = 53;
  9.  
  10. function CalcELFHash(const S : string) : longint; far;
  11. var
  12.   G : longint;
  13.   i : integer;
  14. begin
  15.   Result := 0;
  16.   for i := 1 to length(S) do begin
  17.     Result := (Result shl 4) + ord(S[i]);
  18.     G := Result and $F0000000;
  19.     if (G <> 0) then
  20.       Result := Result xor (G shr 24);
  21.     Result := Result and (not G);
  22.   end;
  23. end;
  24.  
  25. const
  26.   TPEmployees : array [0..32] of string[15] =
  27.     ('Antypas',          'Bolduc',           'Brady',
  28.      'Bucknall',         'Cappellucci',      'Cope',
  29.      'DelRossi',         'Douglas',          'Fairweather',
  30.      'Foley',            'Frerking',         'Geiger',
  31.      'Ghinaudo',         'Horaz',            'Huffman',
  32.      'Hughes',           'Inman',            'Kokkonen',
  33.      'Larsen',           'Leier',            'Medlin',
  34.      'Milner',           'Phillips',         'Reisdorph',
  35.      'Roberts',          'Rogers',           'Rose',
  36.      'Salisbury',        'Trickey',          'Troxell',
  37.      'Turner',           'Warner',           'Welch');
  38.  
  39. var
  40.   i : integer;
  41.   HashTable : ThtHashTableLinear;
  42.  
  43. begin
  44.   HashTable := ThtHashTableLinear.Create(47, CalcELFHash);
  45.   try
  46.     {add all employee names}
  47.     for i := 0 to 32 do begin
  48.       HashTable.Insert(TPEmployees[i], nil);
  49.       HashTable.debugPrint(Format('tstHsh%d.LOG', [i]), false);
  50.     end;
  51.     HashTable.debugPrint('tstHshXX.LOG', true);
  52.     {delete all but 6 employee names}
  53.     for i := 6 to 32 do begin
  54.       HashTable.Delete(TPEmployees[i]);
  55.       HashTable.debugPrint(Format('tstHsh%d.LOG', [50+i]), false);
  56.     end;
  57.     HashTable.debugPrint('tstHshYY.LOG', true);
  58.   finally
  59.     HashTable.Free;
  60.   end;
  61. end.
  62.